package com.fingard.dsp.bank.directbank.abc02;

import com.fingard.FGBiz;
import com.fingard.constant.Format;
import com.fingard.db.JDBCHelper;
import com.fingard.xml.XElement;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.apache.poi.ss.formula.eval.EvaluationException;

import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB001OperBillQryDetail;
import com.fingard.dsp.bank.reqrespobj.elecbillquery.detail.RetAtsB007BillKzsrQryDetail;
import com.fingard.text.StringHelper;
import com.fingard.util.BijectionHashMap;
import com.fingard.util.DateHelper;
import com.fingard.xml.XmlTextReader;
import com.fingard.xml.XmlTextWriter;

import java.math.BigDecimal;
import java.sql.Connection;
import java.text.ParseException;
import java.util.*;

public class ABC02ElecBase extends ABC02Base {
    //持票人ID查询/插入/更新SQL
    //RESERVE1-成员单位名称   RESERVE2-成员单位ID
    protected static final String INSERTCLIENTID = "INSERT INTO REQSEQIDMAPPING(URID,BANKCODE,RESERVE1,RESERVE2) values (?,?,?,?);";
    protected static final String SELECTCLIENTID = "SELECT RESERVE2 FROM REQSEQIDMAPPING WHERE RESERVE1=? AND BANKCODE=?;";
    protected static final String UPDATECLIENTID = "UPDATE REQSEQIDMAPPING SET RESERVE2=? WHERE BANKCODE=? AND RESERVE1=?;";


    public static final BijectionHashMap<String, String> ELE_BILL_TYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_TRANS_FLAG = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_SIGN_FLAG = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_PAY_TYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_RECOURSE_TYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_RECOURSE_REASON = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_EXPIRED_FLAG = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_ISEXPIRED_FLAG = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_DUEPAYTYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_DISCOUNT_TYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_BUS_TYPE = new BijectionHashMap<String, String>();
    public static final BijectionHashMap<String, String> ELE_TRANSCODE = new BijectionHashMap<String, String>();

    static {
        ELE_BILL_TYPE.put("1", "AC01"); //银承
        ELE_BILL_TYPE.put("2", "AC02"); //商承

        ELE_TRANS_FLAG.put("1", "EM00"); //可再转让
        ELE_TRANS_FLAG.put("2", "EM01"); //不可再转让

        ELE_SIGN_FLAG.put("1", "SU00"); //同意
        ELE_SIGN_FLAG.put("2", "SU01"); //拒绝

        ELE_PAY_TYPE.put("1", "SM00");  //线上清算
        ELE_PAY_TYPE.put("2", "SM01"); //线下清算

        ELE_RECOURSE_TYPE.put("1", "RT00");  //拒付追索
        ELE_RECOURSE_TYPE.put("2", "RT01"); //非拒付追索

        ELE_RECOURSE_REASON.put("1", "RC00");  //承兑人被依法宣告破产
        ELE_RECOURSE_REASON.put("2", "RC01"); //承兑人因违法被责令终止活动

        ELE_EXPIRED_FLAG.put("1", "DPF000");//未逾期
        ELE_EXPIRED_FLAG.put("2", "DPF001");//逾期

        ELE_ISEXPIRED_FLAG.put("1", "0");//未逾期
        ELE_ISEXPIRED_FLAG.put("2", "1");//逾期

        ELE_DUEPAYTYPE.put("1", "CC00"); //无条件支付
        ELE_DUEPAYTYPE.put("0", "CC01"); //非无条件支付

        ELE_DISCOUNT_TYPE.put("1", "RM00"); //买断式
        ELE_DISCOUNT_TYPE.put("2", "RM01"); //回购式


//        EBC01-出票
//        EBC02-承兑
//        EBC03-提示收票
//        EBC04-撤票
//        EBC05-背书
//        EBC06-贴现
//        EBC07-回购式贴现赎回
//        EBC08-转贴现
//        EBC09-回购式转贴现赎回
//        EBC10-再贴现
//        EBC11-回购式再贴现赎回
//        EBC12-质押
//        EBC13-质押解除
//        EBC14-保证
//        EBC15-提示付款
//        EBC16-逾期提示付款
//        EBC17-追索通知
//        EBC18-同意清偿
        ELE_BUS_TYPE.put("003", "3");
        ELE_BUS_TYPE.put("002", "2");
        ELE_BUS_TYPE.put("010", "10");
        ELE_BUS_TYPE.put("011", "11");
        ELE_BUS_TYPE.put("012", "12");
        ELE_BUS_TYPE.put("013", "13");
        ELE_BUS_TYPE.put("014", "14");
        ELE_BUS_TYPE.put("015", "15");
        ELE_BUS_TYPE.put("016", "16");
        ELE_BUS_TYPE.put("017", "17");
        ELE_BUS_TYPE.put("018", "18");
        ELE_BUS_TYPE.put("019", "19");
        ELE_BUS_TYPE.put("020", "20");
        ELE_BUS_TYPE.put("021", "21");
        ELE_BUS_TYPE.put("022", "22");
        ELE_BUS_TYPE.put("023", "23");
        /**
         * Created by Bobby on 2017/2/27.
         * 操作标志:
         * 1000-指令申请
         * 1001-出票登记申请
         * 1002-提示承兑申请
         * 1003-提示收票申请
         * 1004-背书转让申请
         * 1005-质押申请
         * 1010-贴现申请
         * 1012-提示付款申请
         * 1013-追索通知申请
         * 1014-同意清偿申请
         * 2000-指令签收
         * 2002-提示承兑签收
         * 2003-提示收票签收
         * 2004-背书转让签收
         * 2006-质押解除签收
         * 2011-回购式贴现赎回签收
         * 2014-同意清偿签收
         * 3000-指令撤回
         * 3001-撤票
         * 3002-提示承兑撤回
         * 3003-提示收票撤回
         * 3004-背书转让撤回
         * 3005-质押撤回
         * 3010-贴现撤回
         * 3012-提示付款撤回
         * 3013-追索通知撤回
         * 3014-同意清偿撤回
         */
//        TRE004	提示收票
//        TRE005	撤票
//        TRE006	背书转让
//        TRE007	贴现
//        TRE012	质押
//        TRE013	解质押
//        TRE014	保证
//        TRE015	提示付款
//        TRE017	追索通知
//        TRE018	同意清偿
//        TRE019	撤销
//        TRE020-承兑回复
//        TRE021-收票回复
//        TRE022-背书转让回复
//        TRE029-质押回复
//        TRE030-质押解除回复
//        TRE031-保证回复
//        TRE034-同意清偿回复
        ELE_TRANSCODE.put("3", "TRE004");
        ELE_TRANSCODE.put("1", "TRE005");
        ELE_TRANSCODE.put("4", "TRE006");
        ELE_TRANSCODE.put("10", "TRE007");
        ELE_TRANSCODE.put("5", "TRE012");
        ELE_TRANSCODE.put("12", "TRE015");
        ELE_TRANSCODE.put("13", "TRE017");
        ELE_TRANSCODE.put("14", "TRE018");
        ELE_TRANSCODE.put("6", "TRE013");
    }

    @SuppressWarnings("deprecation")
    public static String getSeqID() {
        Date date = new Date();
        String hour = "";
        String minute = "";
        String second = "";
        if (date.getHours() < 10) {
            hour = "0" + date.getHours();
        } else {
            hour = String.valueOf(date.getHours());
        }
        if (date.getMinutes() < 10) {
            minute = "0" + date.getMinutes();
        } else {
            minute = String.valueOf(date.getMinutes());
        }

        if (date.getSeconds() < 10) {
            second = "0" + date.getSeconds();
        } else {
            second = String.valueOf(date.getSeconds());
        }
        String seqId = hour + minute + second;
        return seqId + new Random().nextInt(10000);
    }

//    public void CFRT62() throws Exception {
//        String acountnumber = "402001040003008";
//
//        XmlTextWriter writer = new XmlTextWriter();
//        //添加包头
//        ABC02Header header = new ABC02Header();
//        header.CCTransCode = "CFRT62";
//        header.msgType = "0190";
//        header.ReqDateTime = new Date();
//        header.ReqSeqNo = getSeqID();
//        writeEleCommonHead(writer, header);
//
//
//        XmlTextReader billDetailReader = CQRT19("14453489-6", "402001040003008", "1839001800000126");
//        //<EBInfo>
//        //<IdNb>票据号码</IdNb>
//        //<BillTyp>票据种类</BillTyp>
//        //<IssDat>出票日期</IssDat>
//        //<DueDat>到期日</DueDat>
//        //</EBInfo>
//        writer.writeStartElement("EBInfo");
//        writer.writeElementString("IdNb", "021907138599920180111151624215");
//        writer.writeElementString("BillTyp", ELE_BILL_TYPE.getNotNull("2"));
//        writer.writeElementString("IssDat", "2018-02-01");
//        writer.writeElementString("DueDat", "2018-02-01");
//        writer.writeEndElement();
//        //<CollztnBk>
//        //<CbNam>名称</CbNam>
//        //<CbTyp>类别</CbTyp>
//        //<CbOpBnk>开户行行号</CbOpBnk>
//        //<CbOpBnkNam>开户行名称</CbOpBnkNam>
//        //<CbConBnk>承接行行号</CbConBnk>
//        //<CbConBnkNam>承接行名称</CbConBnkNam>
//        //</CollztnBk>
//        writer.writeStartElement("CollztnBk");
//        writer.writeElementString("CbNam", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbNam"));
//        writer.writeElementString("CbTyp", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbTyp"));
//        writer.writeElementString("CbOpBnk", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbOpBnk"));
//        writer.writeElementString("CbOpBnkNam", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbOpBnkNam"));
//        writer.writeElementString("CbConBnk", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbConBnk"));
//        writer.writeElementString("CbConBnkNam", billDetailReader.getFirstText("/ap/Hermes/Collztn/CbConBnkNam"));
//        writer.writeEndElement();
//        //<CollztnPropsr>
//        //<CpsrNam>名称</CpsrNam>
//        //<CpsrTyp>类别</CpsrTyp>
//        //<CpsrOrgCode>组织机构代码</CpsrOrgCode>
//        //<CpsrOpBnk>开户行行号</CpsrOpBnk>
//        //<CpsrOpBnkNam>开户行名称</CpsrOpBnkNam>
//        //<CpsrConBnk>承接行行号</CpsrConBnk>
//        //<CpsrConBnkNam>承接行名称</CpsrConBnkNam>
//        //</CollztnPropsr>
//        writer.writeStartElement("CollztnPropsr");
//        writer.writeElementString("CpsrNam", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrNam"));
//        writer.writeElementString("CpsrTyp", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrTyp"));
//        writer.writeElementString("CpsrOrgCode", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrOrgCode"));
//        writer.writeElementString("CpsrOpBnk", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrOpBnk"));
//        writer.writeElementString("CpsrOpBnkNam", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrOpBnkNam"));
//        writer.writeElementString("CpsrConBnk", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrConBnk"));
//        writer.writeElementString("CpsrConBnkNam", billDetailReader.getFirstText("/ap/Hermes/CollztnPropsr/CpsrConBnkNam"));
//        writer.writeEndElement();
//        //<Note>备注</Note>
//        //<BatchNo>批次号</BatchNo>
//        writer.writeElementString("Note", "");
//        writer.writeElementString("BatchNo", "");
//        writer.writeEndElement();
//        //<Cmp>
//        //<DbAccNo>出质人账号</DbAccNo>
//        //<DbProv>出质人省市代码</DbProv>
//        //<DbCur>出质人货币码</DbCur>
//        //<CrAccNo>质权人帐号</CrAccNo>
//        //</Cmp>
//        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", "402001040003008");
//        writer.writeElementString("DbProv", getConfiguredProvince("402001040003008"));
//        writer.writeElementString("DbCur", getConfiguredCurrency("402001040003008"));
//        writer.writeElementString("CrAccNo", acountnumber);
//        writer.writeEndElement();
//        //<Amt>金额</Amt>
//        writer.writeElementString("Amt", "100.00");
//        //发送银行
//        writer.writeEndDocument();
//        String[] tmpStrRet = sendToBank(writer.toXmlString());
//        System.out.println(Arrays.toString(tmpStrRet));
//    }

    public void writeEleCommonHead(XmlTextWriter xmlTextWriter, ABC02Header header) throws Exception {
        assert header.msgType != null;
        if (StringHelper.isNullOrEmpty(header.CCTransCode)) {
            throw new Exception("未赋值CCTransCode");
        }
        if (StringHelper.isNullOrEmpty(header.ReqSeqNo)) {
            throw new Exception("未赋值ReqSeqNo");
        }


        writeCommonHeader(xmlTextWriter, header);
        xmlTextWriter.writeStartElement("Hermes");
        xmlTextWriter.writeStartElement("Head");
        xmlTextWriter.writeElementString("MsgTyp", header.msgType);
        xmlTextWriter.writeEndElement(); //结束head


    }

    public void populateCQRT09(RetAtsB001OperBillQryDetail detail, String account, String actArea, String billCur, String billNo, String busNo) throws Exception {
        XmlTextReader reader = CQRT09(account, actArea, billCur, billNo, busNo);
        if (reader == null) {
            return;
        }
        detail.issDate = reader.getFirstText("/ap/Hermes/EBInfo/IssDat");//	出票日
        detail.dueDate = reader.getFirstText("/ap/Hermes/EBInfo/DueDat");//	到期日
        detail.applyBnkName = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnkNam");
        detail.applyBnkCode = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnk");
        detail.applyAct = reader.getFirstText("/ap/Hermes/DrawerInfo/FrAccNo");
        detail.applyCode = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOrgCode");
        detail.applyName = reader.getFirstText("/ap/Hermes/DrawerInfo/FrNam");
        detail.receName = reader.getFirstText("/ap/Hermes/ReserInfo/ResNam");
        detail.receBnkName = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnkNam");
        detail.receBnkCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnk");
        detail.receCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOrgCode");
        detail.memo = reader.getFirstText("/ap/Hermes/AcceptInfo/Note");
        detail.invoiceNo = reader.getFirstText("/ap/Hermes/AcceptInfo/InvoiceNo");
        detail.contractNo = reader.getFirstText("/ap/Hermes/AcceptInfo/ContNo");
    }

    public XmlTextReader CQRT09(String account, String area, String billCur, String billNo, String busNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT09";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busNo);
        writer.writeElementString("TransCode", "TRE021");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, area));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }

    /**
     * 查询可承兑票据
     */
    public XmlTextReader CQRT07(
            String account, String actArea, String billCur, String billNo, String busNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT07";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busNo);
        writer.writeElementString("TransCode", "TRE020");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }


    /**
     * 查询可提示签收票据
     */
//    public XmlTextReader CQRT08(
//            String account, String billNo) throws Exception {
//        ABC02Header header = new ABC02Header();
//        XmlTextWriter writer = new XmlTextWriter();
//
//        header.CCTransCode = "CQRT08";
//        header.msgType = "0032";
//        header.ReqDateTime = new Date();
//        header.ReqSeqNo = reqHeader.transSeqID;
//        writeEleCommonHead(writer, header);
//
//        //<EBInfo>
//        //<IdNb>票据号码</IdNb>
//        //</EBInfo>
//        writer.writeElementString("IdNb", billNo);
//        writer.writeEndElement();
//        //<Cmp>
//        //<DbAccNo>查询人账号</DbAccNo>
//        //<DbProv>查询人省市代码</DbProv>
//        //<DbCur>查询人货币码</DbCur>
//        //</Cmp>
//        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
//        writer.writeEndElement();
//
//        //发送银行
//        writer.writeEndDocument();
//        String[] tmpStrRet = sendToBank(writer.toXmlString());
//        if (tmpStrRet[0].length() == 0) {
//            StringBuilder tmpSbMsg = new StringBuilder();
//            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//            if (tmpBkReader != null) {
//                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
//                String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
//                String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
//                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
//                    return tmpBkReader;
//                }
//            }
//        }
//        return null;
//    }
    public static String getReqSeqId(String value) {
        return StringUtils.isNumeric(value) ? value : "";
    }

    public XmlTextReader CQRT18(String account, String actArea, String billCur, String billNo, String busiNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT18";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busiNo);
        writer.writeElementString("TransCode", "TRE029");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }

    public void populateCQRT11(RetAtsB001OperBillQryDetail respDetail, String account, String actArea, String billCur, String billNo, String busiNo) throws Exception {
        XmlTextReader reader = CQRT11(account, actArea, billCur, billNo, busiNo);
        if (reader == null) {
            return;
        }
        respDetail.issDate = reader.getFirstText("/ap/Hermes/EBInfo/IssDat");//	出票日
        respDetail.dueDate = reader.getFirstText("/ap/Hermes/EBInfo/DueDat");//	到期日
        respDetail.applyName = reader.getFirstText("/ap/Hermes/Endrsr/EsrNam");//Hermes/Endrsr/EsrNam	背书人名称
        respDetail.applyCode = reader.getFirstText("/ap/Hermes/Endrsr/EsrOrgCode");//Hermes/Endrsr/EsrOrgCode	背书人组织机构代码
        respDetail.applyAct = reader.getFirstText("/ap/Hermes/Endrsr/EsrAccNo");//Hermes/Endrsr/EsrAccNo	背书人账号
        respDetail.applyBnkCode = reader.getFirstText("/ap/Hermes/Endrsr/EsrOpBnk");//Hermes/Endrsr/EsrOpBnk	背书人开户行行号
        respDetail.applyBnkName = reader.getFirstText("/ap/Hermes/Endrsr/EsrOpBnkNam");//Hermes/Endrsr/EsrOpBnkNam	背书人开户行行号名称
        respDetail.applyDate = reader.getFirstText("/ap/Hermes/Endrsmt/EsmtDat");//Hermes/Endrsmt/EsmtDat	背书申请日期
        respDetail.receName = reader.getFirstText("/ap/Hermes/ReserInfo/ResNam");//Hermes/ReserInfo/ResNam	回复人名称
        respDetail.receCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOrgCode");//Hermes/ReserInfo/ResOrgCode	回复人组织机构代码
        respDetail.receBnkCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnk");//Hermes/ReserInfo/ResOpBnk	回复人开户行行号
        respDetail.receBnkName = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnkNam");//Hermes/ReserInfo/ResOpBnkNam	回复人开户行名称
        respDetail.memo = reader.getFirstText("/ap/Hermes/Endrsmt/EsmtNote");
        respDetail.invoiceNo = reader.getFirstText("/ap/Hermes/AcceptInfo/InvoiceNo");
        respDetail.contractNo = reader.getFirstText("/ap/Hermes/AcceptInfo/ContNo");
    }

    public void populateCQRT20(RetAtsB001OperBillQryDetail respDetail, String account, String actArea, String billCur, String billNo, String busiNo) throws Exception {
        XmlTextReader reader = CQRT20(account, actArea, billCur, billNo, busiNo);
        if (reader == null) {
            return;
        }
        respDetail.issDate = reader.getFirstText("/ap/Hermes/EBInfo/IssDat");//	出票日
        respDetail.dueDate = reader.getFirstText("/ap/Hermes/EBInfo/DueDat");//	到期日
        respDetail.applyDate = reader.getFirstText("/ap/Hermes/RCollztn/RztnDat");//Hermes/RCollztn/RztnDat	质押解除申请日期
        respDetail.memo = reader.getFirstText("/ap/Hermes/RCollztn/RztnNote");//Hermes/RCollztn/RztnNote	质权人备注
        respDetail.applyName = reader.getFirstText("/ap/Hermes/CollztnBk/CbNam");//Hermes/CollztnBk/CbNam	质权人名称
        respDetail.applyCode = reader.getFirstText("/ap/Hermes/CollztnBk/CbOrgCode");//Hermes/CollztnBk/CbOrgCode 	质权人组织机构代码
        respDetail.applyAct = reader.getFirstText("/ap/Hermes/CollztnBk/CbAccNo");//Hermes/CollztnBk/CbAccNo 	质权人账号
        respDetail.applyBnkCode = reader.getFirstText("/ap/Hermes/CollztnBk/CbOpBnk");//Hermes/CollztnBk/CbOpBnk 	质权人开户行行号
        respDetail.applyBnkName = reader.getFirstText("/ap/Hermes/CollztnBk/CbOpBnkNam");//Hermes/CollztnBk/CbOpBnkNam 	质权人开户行行号名称称
        respDetail.receName = reader.getFirstText("/ap/Hermes/ReserInfo/ResNam");//Hermes/ReserInfo/ResNam	回复人名称
        respDetail.receCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOrgCode");//Hermes/ReserInfo/ResOrgCode	回复人组织机构代码
        respDetail.receBnkCode = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnk");//Hermes/ReserInfo/ResOpBnk	回复人开户行行号
        respDetail.receBnkName = reader.getFirstText("/ap/Hermes/ReserInfo/ResOpBnkNam");//Hermes/ReserInfo/ResOpBnkNam	回复人开户行名称
        respDetail.memo = reader.getFirstText("/ap/Hermes/RCollztn/RztnNote");
    }

    /**
     * 查询可背书回复票据
     */
    public XmlTextReader CQRT20(
            String account, String actArea, String billCur, String billNo, String busiNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT20";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busiNo);
        writer.writeElementString("TransCode", "TRE030");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }

    /**
     * 以yyyy-MM-dd格式对日期进行格式化
     */
    public String formatDate10(String date) throws ParseException, EvaluationException {
        if (StringUtils.isEmpty(date)) {
            return "";
        }
        if (date.length() > 19) {
            date = date.substring(0, 19);
        }
        return DateFormatUtils.format(DateHelper.convertToDateExtra(date), "yyyy-MM-dd");
    }

    public String formatDecimal2(String amount) {
        if (StringUtils.isEmpty(amount)) {
            return "";
        }
        return new BigDecimal(amount).setScale(2).toPlainString();
    }

    public String formatDate19(String dateStr) throws ParseException {
        if (StringUtils.isEmpty(dateStr)) {
            return "";
        }
        Date date = DateHelper.convertToDateExtra(dateStr);
        return DateFormatUtils.format(date, "yyyy-MM-dd HH:mm:ss");
    }

    /**
     * 翻译清算类型名称
     */
    public String convertPayTypeName(String payType) throws Exception {
        return ELE_PAY_TYPE.getNotNull(payType);
    }

    public String getConfiguredCurrency(String accountnumber) throws Exception {
        String value = getBankConfig().getMapValueByKey("eledraftAccountInfo", accountnumber);
        if (StringHelper.isNullOrEmpty(value)) {
            return "";
        }
        return value.split(",")[0];
    }

//    public String getConfiguredProvince(String accountnumber) throws Exception {
//        String value = getBankConfig().getMapValueByKey("eledraftAccountInfo", accountnumber);
//        if (StringHelper.isNullOrEmpty(value)) {
//            return "";
//        }
//        return value.split(",")[1];
//    }

    public XmlTextReader CQRT11(
            String account, String actArea, String billCur, String billNo, String busiNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT11";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);


        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busiNo);
        writer.writeElementString("TransCode", "TRE022");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                tmpBkReader.getFirstText("/ap/RespInfo");
                tmpBkReader.getFirstText("/ap/RxtInfo");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }


    /**
     * 查询可撤票票据
     */
    public RetAtsB001OperBillQryDetail CQRT25(String account, String actArea, String billCur, String billNo, Map<String, String> extraAttributes) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT25";
        header.msgType = "0042";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //</EBInfo>
        writer.writeElementString("IdNb", billNo);
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        RetAtsB001OperBillQryDetail respDetail = null;
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                extraAttributes.put("RespCode", tmpRetCode);
                extraAttributes.put("RespInfo", tmpRetInfo);
                extraAttributes.put("RxtInfo", tmpRetRxtInfo);
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    respDetail = new RetAtsB001OperBillQryDetail();
                    respDetail.billNo = tmpBkReader.getFirstText("/ap/Hermes/EBInfo/IdNb");//Hermes/EBInfo/IdNb	票据号码
                    respDetail.billAmt = tmpBkReader.getFirstText("/ap/Hermes/EBInfo/BillAmt");//Hermes/EBInfo/BillAmt	票据金额
                    respDetail.billType = ELE_BILL_TYPE.reverse().getOrDefault(
                            tmpBkReader.getFirstText("/ap/Hermes/EBInfo/BillTyp"),//Hermes/EBInfo/BillTyp	票据种类
                            tmpBkReader.getFirstText("/ap/Hermes/EBInfo/BillTypNam")//Hermes/EBInfo/BillTypNam	票据种类名称
                    );
                    respDetail.transFlag = ELE_TRANS_FLAG.reverse().getOrDefault(
                            tmpBkReader.getFirstText("/ap/Hermes/EBInfo/TransFlg"),//Hermes/EBInfo/TransFlg	不得转让标记
                            tmpBkReader.getFirstText("/ap/Hermes/EBInfo/TransFlgNam")//Hermes/EBInfo/TransFlgNam	不得转让标记名称
                    );
                    respDetail.issDate = tmpBkReader.getFirstText("/ap/Hermes/EBInfo/IssDat");//Hermes/EBInfo/IssDat	出票日期
                    respDetail.dueDate = tmpBkReader.getFirstText("/ap/Hermes/EBInfo/DueDat");//Hermes/EBInfo/DueDat	到期日
                    respDetail.mustPay = ELE_DUEPAYTYPE.reverse().getOrDefault(
                            tmpBkReader.getFirstText("/ap/Hermes/BillInfo/DuePayTyp"),//Hermes/BillInfo/DuePayTyp	到期无条件支付承诺
                            tmpBkReader.getFirstText("/ap/Hermes/BillInfo/DuePayTypNam")//Hermes/BillInfo/DuePayTypNam	到期无条件支付承诺名称
                    );
                    respDetail.contractNo = tmpBkReader.getFirstText("/ap/Hermes/BillInfo/ContNo");//Hermes/BillInfo/ContNo	交易合同编号
                    respDetail.invoiceNo = tmpBkReader.getFirstText("/ap/Hermes/BillInfo/InvoiceNo");//Hermes/BillInfo/InvoiceNo	发票号码
                    respDetail.drawName = tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrNam");//Hermes/DrawerInfo/FrNam	出票人名称
                    respDetail.drawCode = tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrOrgCode");//Hermes/DrawerInfo/FrOrgCode	组织机构代码
                    respDetail.drawAct = tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrAccNo");//Hermes/DrawerInfo/FrAccNo	出票人账号
                    extraAttributes.put("FrTyp", tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrTyp")); //Hermes/DrawerInfo/FrTyp	出票人类别
                    extraAttributes.put("FrTypNam", tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrTypNam")); //Hermes/DrawerInfo/FrTypNam	出票人类别
                    respDetail.drawBnkCode = tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnk");//Hermes/DrawerInfo/FrOpBnk	出票人开户行行号
                    respDetail.drawBnkName = tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnkNam");//Hermes/DrawerInfo/FrOpBnkNam	出票人开户行名称
                    extraAttributes.put("FrConBnk", tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrConBnk")); //Hermes/DrawerInfo/FrConBnk	承接行行号
                    extraAttributes.put("FrConBnkNam", tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrConBnkNam")); //Hermes/DrawerInfo/FrConBnkNam	承接行名称
                    extraAttributes.put("FrTrdAttr", tmpBkReader.getFirstText("/ap/Hermes/DrawerInfo/FrTrdAttr")); //Hermes/DrawerInfo/FrTrdAttr	出票人行业属性
                    respDetail.accpName = tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepNam");//Hermes/AccepteInfor/AcepNam	承兑人名称
                    extraAttributes.put("AcepTyp", tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepTyp"));//Hermes/AccepteInfor/AcepTyp	承兑人类别
                    extraAttributes.put("AcepTypNam", tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepTypNam"));//Hermes/AccepteInfor/AcepTypNam	承兑人类别名称
                    respDetail.accpCode = tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepOrgCode");//Hermes/AccepteInfor/AcepOrgCode	承兑人组织机构代码
                    respDetail.accpAct = tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepAccNo");//Hermes/AccepteInfor/AcepAccNo	承兑人账号
                    respDetail.accpBnkCode = tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepOpBnk");//Hermes/AccepteInfor/AcepOpBnk	承兑人开户行行号
                    respDetail.accpBnkName = tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepOpBnkNam");//Hermes/AccepteInfor/AcepOpBnkNam	承兑人开户行名称
                    extraAttributes.put("AcepConBnk", tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepConBnk"));//Hermes/AccepteInfor/AcepConBnk	承接行行号
                    extraAttributes.put("AcepConBnkNam", tmpBkReader.getFirstText("/ap/Hermes/AccepteInfor/AcepConBnkNam"));//Hermes/AccepteInfor/AcepConBnkNam	承接行名称
                    respDetail.payeeName = tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToNam");//Hermes/PayeeInfo/ToNam	收票人名称
                    extraAttributes.put("ToTyp", tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToTyp"));//Hermes/PayeeInfo/ToTyp	收票人类别
                    extraAttributes.put("ToTypNam", tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToTypNam"));//Hermes/PayeeInfo/ToTypNam	收票人类别名称
                    respDetail.payeeCode = tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToNam");//Hermes/PayeeInfo/ToOrgCode	收票人组织机构代码
                    respDetail.payeeAct = tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToAccNo");//Hermes/PayeeInfo/ToAccNo	收票人账号
                    respDetail.payeeBnkCode = tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToOpBnk");//Hermes/PayeeInfo/ToOpBnk	收票人开户行行号
                    respDetail.payeeBnkName = tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToOpBnkNam");//Hermes/PayeeInfo/ToOpBnkNam	收票人开户行名称
                    extraAttributes.put("ToConBnk", tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToConBnk"));//Hermes/PayeeInfo/ToConBnk	承接行行号
                    extraAttributes.put("ToConBnkNam", tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToConBnkNam"));//Hermes/PayeeInfo/ToConBnkNam	承接行名称
                    extraAttributes.put("ToTrdAttr", tmpBkReader.getFirstText("/ap/Hermes/PayeeInfo/ToTrdAttr"));//Hermes/PayeeInfo/ToTrdAttr	收票人行业属性
                }
            }
        }
        return respDetail;
    }


    public XmlTextReader CQRT05(String account, String actArea, String billCur) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();


        header.CCTransCode = "CQRT05";
        header.msgType = "2002";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<Cmp>
        //<DbAccNo>账号</DbAccNo>
        //<DbProv>省市代码</DbProv>
        //<DbCur>货币码</DbCur>
        //</Cmp>
        writer.writeEndElement();
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();


        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }

    public XmlTextReader CQRT10(String account, String actArea, String billCur, String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();


        header.CCTransCode = "CQRT10";
        header.msgType = "0102";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);
        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //</EBInfo>
        writer.writeElementString("IdNb", billNo);
        //<Cmp>
        //<DbAccNo>账号</DbAccNo>
        //<DbProv>省市代码</DbProv>
        //<DbCur>货币码</DbCur>
        //</Cmp>
        writer.writeEndElement();
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();


        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }


        return null;
    }

//    public XmlTextReader CQRT19(String orgcode, String actnum, String busNo) throws Exception {
//        ABC02Header header = new ABC02Header();
//        XmlTextWriter writer = new XmlTextWriter();
//
//
//        header.CCTransCode = "CQRT19";
//        header.msgType = "0192";
//        header.ReqDateTime = new Date();
//        header.ReqSeqNo = reqHeader.transSeqID;
//        writeEleCommonHead(writer, header);
//
//
//        //<QryOrgCode>查询人组织机构代码</QryOrgCode>
//        //<BusCode>业务编码</BusCode>
//        writer.writeElementString("QryOrgCode", orgcode);
//        writer.writeElementString("BusCode", busNo);
//        writer.writeEndElement();
//        //<Cmp>
//        //<DbAccNo>账号</DbAccNo>
//        //<DbProv>省市代码</DbProv>
//        //<DbCur>货币码</DbCur>
//        //</Cmp>
//        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", actnum);
//        writer.writeElementString("DbProv", getConfiguredProvince(actnum));
//        writer.writeElementString("DbCur", getConfiguredCurrency(actnum));
//        writer.writeEndElement();
//
//
//        //发送银行
//        writer.writeEndDocument();
//        String[] tmpStrRet = sendToBank(writer.toXmlString());
//        if (tmpStrRet[0].length() == 0) {
//            StringBuilder tmpSbMsg = new StringBuilder();
//            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
//            if (tmpBkReader != null) {
//                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
//                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
//                    return tmpBkReader;
//                }
//            }
//        }
//
//
//        return null;
//    }

    public void populateBillDetail(RetAtsB001OperBillQryDetail detail, XmlTextReader reader) throws Exception {
        if (reader != null) {
            String tmpRetCode = reader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                detail.billStatus = reader.getFirstText("/ap/Hermes/EBInfo/BillSta");//Hermes/EBInfo/BillSta	票据状态
                detail.billNo = reader.getFirstText("/ap/Hermes/EBInfo/IdNb");//Hermes/EBInfo/IdNb	票据号码
                detail.billAmt = reader.getFirstText("/ap/Hermes/EBInfo/BillAmt");//Hermes/EBInfo/BillAmt	票据金额
                detail.billType = ELE_BILL_TYPE.reverse().getOrDefault(
                        reader.getFirstText("/ap/Hermes/EBInfo/BillTyp"),//Hermes/EBInfo/BillTyp	票据种类
                        reader.getFirstText("/ap/Hermes/EBInfo/BillTypNam")//Hermes/EBInfo/BillTypNam	票据种类名称
                );
                detail.transFlag = ELE_TRANS_FLAG.reverse().getOrDefault(
                        reader.getFirstText("/ap/Hermes/EBInfo/TransFlg"),//Hermes/EBInfo/TransFlg	不得转让标记
                        reader.getFirstText("/ap/Hermes/EBInfo/TransFlgNam")//Hermes/EBInfo/TransFlgNam	不得转让标记名称
                );
                detail.issDate = reader.getFirstText("/ap/Hermes/EBInfo/IssDat");//Hermes/EBInfo/IssDat	出票日期
                detail.dueDate = reader.getFirstText("/ap/Hermes/EBInfo/DueDat");//Hermes/EBInfo/DueDat	到期日
                detail.mustPay = ELE_DUEPAYTYPE.reverse().getOrDefault(
                        reader.getFirstText("/ap/Hermes/BillInfo/DuePayTyp"),//Hermes/BillInfo/DuePayTyp	到期无条件支付承诺
                        reader.getFirstText("/ap/Hermes/BillInfo/DuePayTypNam")//Hermes/BillInfo/DuePayTypNam	到期无条件支付承诺名称
                );
                detail.contractNo = reader.getFirstText("/ap/Hermes/BillInfo/ContNo");//Hermes/BillInfo/ContNo	交易合同编号
                detail.invoiceNo = reader.getFirstText("/ap/Hermes/BillInfo/InvoiceNo");//Hermes/BillInfo/InvoiceNo	发票号码
                detail.drawName = reader.getFirstText("/ap/Hermes/DrawerInfo/FrNam");//Hermes/DrawerInfo/FrNam	出票人名称
                detail.drawCode = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOrgCode");//Hermes/DrawerInfo/FrOrgCode	组织机构代码
                detail.drawAct = reader.getFirstText("/ap/Hermes/DrawerInfo/FrAccNo");//Hermes/DrawerInfo/FrAccNo	出票人账号
                detail.drawBnkCode = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnk");//Hermes/DrawerInfo/FrOpBnk	出票人开户行行号
                detail.drawBnkName = reader.getFirstText("/ap/Hermes/DrawerInfo/FrOpBnkNam");//Hermes/DrawerInfo/FrOpBnkNam	出票人开户行名称
                detail.accpName = reader.getFirstText("/ap/Hermes/AccepteInfor/AcepNam");//Hermes/AccepteInfor/AcepNam	承兑人名称
                detail.accpCode = reader.getFirstText("/ap/Hermes/AccepteInfor/AcepOrgCode");//Hermes/AccepteInfor/AcepOrgCode	承兑人组织机构代码
                detail.accpAct = reader.getFirstText("/ap/Hermes/AccepteInfor/AcepAccNo");//Hermes/AccepteInfor/AcepAccNo	承兑人账号
                detail.accpBnkCode = reader.getFirstText("/ap/Hermes/AccepteInfor/AcepOpBnk");//Hermes/AccepteInfor/AcepOpBnk	承兑人开户行行号
                detail.accpBnkName = reader.getFirstText("/ap/Hermes/AccepteInfor/AcepOpBnkNam");//Hermes/AccepteInfor/AcepOpBnkNam	承兑人开户行名称
                detail.payeeName = reader.getFirstText("/ap/Hermes/PayeeInfo/ToNam");//Hermes/PayeeInfo/ToNam	收票人名称
                detail.payeeCode = reader.getFirstText("/ap/Hermes/PayeeInfo/ToNam");//Hermes/PayeeInfo/ToOrgCode	收票人组织机构代码
                detail.payeeAct = reader.getFirstText("/ap/Hermes/PayeeInfo/ToAccNo");//Hermes/PayeeInfo/ToAccNo	收票人账号
                detail.payeeBnkCode = reader.getFirstText("/ap/Hermes/PayeeInfo/ToOpBnk");//Hermes/PayeeInfo/ToOpBnk	收票人开户行行号
                detail.payeeBnkName = reader.getFirstText("/ap/Hermes/PayeeInfo/ToOpBnkNam");//Hermes/PayeeInfo/ToOpBnkNam	收票人开户行名称
                detail.contractNo = reader.getFirstText("/ap/Hermes/BillInfo/ContNo");//Hermes/BillInfo/ContNo	交易合同编号
                detail.invoiceNo = reader.getFirstText("/ap/Hermes/BillInfo/InvoiceNo");//Hermes/BillInfo/InvoiceNo	发票号码
            }
        }
    }

    public XmlTextReader CQRT14(String account, String actArea, String billCur, String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT14";
        header.msgType = "1017";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //</EBInfo>
        writer.writeElementString("IdNb", billNo);
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }
        return null;
    }

    public XmlTextReader CQRM10(String account, String actArea, String billCur, String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRM10";
        header.msgType = "0222";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<IdNb>票据号码</IdNb>
        writer.writeElementString("IdNb", billNo);
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", account);
//        writer.writeElementString("DbProv", getConfiguredProvince(account));
//        writer.writeElementString("DbCur", getConfiguredCurrency(account));
        writer.writeElementString("DbAccNo", getAbcAccNo(account));
        writer.writeElementString("DbProv", getAbcAccProv(account, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();


        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }


        return null;
    }

    public String CQRT06(String bankCode) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT06";
        header.msgType = "2004";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<Bnk>行号</Bnk>
        writer.writeElementString("Bnk", bankCode);

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader.getFirstText("/ap/Hermes/BnkNam");
            }
        }
        return null;
    }

    public XmlTextReader CQRT13(String accountNumber, String actArea, String billCur, String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT13";
        header.msgType = "0202";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //</EBInfo>
        writer.writeElementString("IdNb", billNo);
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", accountNumber);
//        writer.writeElementString("DbProv", getConfiguredProvince(accountNumber));
//        writer.writeElementString("DbCur", getConfiguredCurrency(accountNumber));
        writer.writeElementString("DbAccNo", getAbcAccNo(accountNumber));
        writer.writeElementString("DbProv", getAbcAccProv(accountNumber, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }
        return null;
    }

    public void populateCQRT22(RetAtsB007BillKzsrQryDetail detail, String accountNumber, String actArea, String billCur, String id) throws Exception {
        XmlTextReader reader = CQRT22(accountNumber, actArea, billCur, id);
        if (reader == null) {
            return;
        }
        detail.receAct = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprAccNo");
        detail.receName = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprNam");
        detail.receCode = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprOrgCode");
        detail.receBnkCode = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprOpBnk");
        detail.receBnkName = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprOpBnkNam");
        detail.receAct = reader.getFirstText("/ap/Hermes/RcvgPrsnOfRcrs/RprAccNo");
    }

    public XmlTextReader CQRT22(String accountNumber, String actArea, String billCur, String id) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT22";
        header.msgType = "0224";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        XmlTextReader accountOrgDetailReadedr = CQRT05(accountNumber, actArea, billCur);

        //<Id>ID</Id>
        //<QryOrgCode>查询人组织机构代码</QryOrgCode>
        writer.writeElementString("Id", id);
        writer.writeElementString("QryOrgCode", accountOrgDetailReadedr.getFirstText("/ap/Hermes/OrgCode"));
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", accountNumber);
//        writer.writeElementString("DbProv", getConfiguredProvince(accountNumber));
//        writer.writeElementString("DbCur", getConfiguredCurrency(accountNumber));
        writer.writeElementString("DbAccNo", getAbcAccNo(accountNumber));
        writer.writeElementString("DbProv", getAbcAccProv(accountNumber, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }
        return null;
    }

    public XmlTextReader CQRT23(String busNo, String accountNumber, String actArea, String billCur) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT23";
        header.msgType = "0232";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        XmlTextReader accountOrgDetailReadedr = CQRT05(accountNumber, actArea, billCur);

        //<BusCode>业务编号</BusCode>
        //<QryOrgCode>查询人组织机构代码</QryOrgCode>
        writer.writeElementString("BusCode", busNo);
        writer.writeElementString("QryOrgCode", accountOrgDetailReadedr.getFirstText("/ap/Hermes/OrgCode"));
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", accountNumber);
//        writer.writeElementString("DbProv", getConfiguredProvince(accountNumber));
//        writer.writeElementString("DbCur", getConfiguredCurrency(accountNumber));
        writer.writeElementString("DbAccNo", getAbcAccNo(accountNumber));
        writer.writeElementString("DbProv", getAbcAccProv(accountNumber, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }
        return null;
    }

    public XmlTextReader CQRT24(String billNo, String busNo, String accountNumber, String actArea, String billCur) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();

        header.CCTransCode = "CQRT24";
        header.msgType = "0313";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);

        //<EBInfo>
        //<IdNb>票据号码</IdNb>
        //<BusCode>业务编码</BusCode>
        //<TransCode>交易代码</TransCode>
        //</EBInfo>
        writer.writeStartElement("EBInfo");
        writer.writeElementString("IdNb", billNo);
        writer.writeElementString("BusCode", busNo);
        writer.writeElementString("TransCode", "TRE034");
        writer.writeEndElement();
        writer.writeEndElement();
        //<Cmp>
        //<DbAccNo>查询人账号</DbAccNo>
        //<DbProv>查询人省市代码</DbProv>
        //<DbCur>查询人货币码</DbCur>
        //</Cmp>
        writer.writeStartElement("Cmp");
//        writer.writeElementString("DbAccNo", accountNumber);
//        writer.writeElementString("DbProv", getConfiguredProvince(accountNumber));
//        writer.writeElementString("DbCur", getConfiguredCurrency(accountNumber));
        writer.writeElementString("DbAccNo", getAbcAccNo(accountNumber));
        writer.writeElementString("DbProv", getAbcAccProv(accountNumber, actArea));
        String dbCur = convertCurToBank(billCur);
        writer.writeElementString("DbCur", StringHelper.hasAnyChar(dbCur) ? dbCur : "01");
        writer.writeEndElement();

        //发送银行
        writer.writeEndDocument();
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
            if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                return tmpBkReader;
            }
        }
        return null;
    }


    //票据池内相关电票接口，银行要求上送“持票单位ID”
    //持票人ID查询CQRM15（消息类型5420）
    public String getClientId(String bankCode, String accountName) throws Exception {
        WriteBankLogLn("全量查询持票人ID，调用CQRM15接口...");
        //查询全量持票单位ID
        Connection conn = FGBiz.getLocalDbConn();
        boolean ishasClientId = false;//判断全量查询的持票人ID是否有与想要查询客户名称匹配的ID
        StringBuilder returnMsg = new StringBuilder();
        try {
            XmlTextWriter writerXml = new XmlTextWriter();
            ABC02Header header = new ABC02Header();
            header.CCTransCode = "CQRM15";
            header.msgType = "5420";
            header.ReqDateTime = new Date();
            header.ReqSeqNo = reqHeader.transSeqID;
            writeBillPoolCommonHead(writerXml, header);
            writerXml.writeElementString("ClientGroup", "0");//成员单位范围 （0：全部成员单位/1：集中管理成员单位）
            writerXml.writeEndElement();//Hermes
            writerXml.writeStartElement("ap");
            writerXml.writeStartElement("Cmp");
            writerXml.writeElementString("ConFlag", "", true);//是否加入池融资 Y/N(Y表示只查加入了票据池融资的客户;N表示只查未加入票据池融资的客户如果送空表示查询全部
            writerXml.writeEndDocument();

            String[] tmpStrRet = sendToBank(writerXml.toXmlString(), "CQRM15", "CQRM15");

            if (tmpStrRet[0].length() == 0) {
                StringBuilder tmpSbMsg = new StringBuilder();
                XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
                if (tmpBkReader != null) {
                    String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                    String tmpRetInfo = tmpBkReader.getFirstText("/ap/RespInfo");
                    String tmpRetRxtInfo = tmpBkReader.getFirstText("/ap/RxtInfo");
                    if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                        while (tmpBkReader.read("/ap/SClientList/SClientInfo")) {
                            XElement readXElement = tmpBkReader.readedXElement;
                            String clientName = readXElement.getSingleTextNotNull("ClientName").trim();//成员单位名称
                            String clientID = readXElement.getSingleTextNotNull("ClientId").trim();//成员单位ID
                            if (clientName.equals(accountName)) {
                                ishasClientId = true;
                            }
                            Map<String, Object> map = JDBCHelper.execQuerySingle(conn, SELECTCLIENTID, new Object[]{clientName, bankCode});
                            if (map.size() == 0) {
                                String uuid = UUID.randomUUID().toString().replaceAll("-", "");
                                JDBCHelper.update(conn, INSERTCLIENTID, new Object[]{uuid, bankCode, clientName, clientID});
                            } else {
                                JDBCHelper.update(conn, UPDATECLIENTID, new Object[]{clientID, bankCode, clientName});
                            }
                        }
                    } else {
                        if (!StringHelper.isNullOrEmpty(tmpRetInfo)) {
                            returnMsg.append("持票人ID查询报错：" + tmpRetInfo + ";");
                        } else {
                            returnMsg.append("持票人ID查询报错：" + tmpRetRxtInfo + ";");
                        }
                    }
                } else {
                    returnMsg.append("持票人ID查询报错：" + tmpSbMsg.toString() + ";");
                }
            } else {
                returnMsg.append("持票人ID查询报错：" + tmpStrRet[1] + ";");
            }
        } catch (Exception e) {
            returnMsg.append("持票人ID查询异常，详情查看日志");
            WriteBankLogLn("持票人ID查询报错:" + e.getMessage());
        } finally {
            conn.close();
        }
        if (!ishasClientId) {
            returnMsg.append("调用持票人ID查询CQRM15查询与[" + accountName + "]匹配的客户名称，没有对应的持票人ID");
        }

        if (returnMsg.length() > 0) {
            return returnMsg.toString();
        } else {
            return "";
        }
    }

    public void writeBillPoolCommonHead(XmlTextWriter xmlTextWriter, ABC02Header p_bankHeader) throws Exception {
        if (StringHelper.isNullOrEmpty(p_bankHeader.CCTransCode)) {
            throw new Exception("未赋值CCTransCode");
        }
        if (StringHelper.isNullOrEmpty(p_bankHeader.ReqSeqNo)) {
            throw new Exception("未赋值ReqSeqNo");
        }
        xmlTextWriter.writeStartDocument();
        xmlTextWriter.writeStartElement("ap");
        xmlTextWriter.writeElementString("CCTransCode", p_bankHeader.CCTransCode);
        xmlTextWriter.writeElementString("ProductID", "ICC");
        xmlTextWriter.writeElementString("ChannelType", "ERP");
        xmlTextWriter.writeElementString("CorpNo", bankFront.org);//企业技监局号码/客户号
        xmlTextWriter.writeElementString("OpNo", bankFront.operator);//企业操作员编号
        xmlTextWriter.writeElementString("AuthNo", "");
        xmlTextWriter.writeElementString("ReqSeqNo", p_bankHeader.ReqSeqNo);
        if (p_bankHeader.ReqDateTime == null) {
            p_bankHeader.ReqDateTime = new Date();
        }
        xmlTextWriter.writeElementString("ReqDate", Format.Date8Format.format(p_bankHeader.ReqDateTime));
        xmlTextWriter.writeElementString("ReqTime", Format.Time6Format.format(p_bankHeader.ReqDateTime));
        xmlTextWriter.writeElementClosed("Sign");


        xmlTextWriter.writeStartElement("Hermes");
        xmlTextWriter.writeStartElement("Head");
        xmlTextWriter.writeElementString("MsgTyp", p_bankHeader.msgType);
        xmlTextWriter.writeEndElement(); //结束head

    }

    public XmlTextReader CQRT36(String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();


        header.CCTransCode = "CQRT36";
        header.msgType = "5102";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);
        writer.writeElementString("IdNb", billNo);//票据号码
        writer.writeEndDocument();

        //发送银行
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }

    public XmlTextReader CQRT34(String billNo) throws Exception {
        ABC02Header header = new ABC02Header();
        XmlTextWriter writer = new XmlTextWriter();


        header.CCTransCode = "CQRT34";
        header.msgType = "5202";
        header.ReqDateTime = new Date();
        header.ReqSeqNo = reqHeader.transSeqID;
        writeEleCommonHead(writer, header);
        writer.writeElementString("IdNb", billNo);//票据号码
        writer.writeEndDocument();

        //发送银行
        String[] tmpStrRet = sendToBank(writer.toXmlString());
        if (tmpStrRet[0].length() == 0) {
            StringBuilder tmpSbMsg = new StringBuilder();
            XmlTextReader tmpBkReader = loadBankRespXmlReader(tmpStrRet[1], tmpSbMsg);
            if (tmpBkReader != null) {
                String tmpRetCode = tmpBkReader.getFirstText("/ap/RespCode");
                if (tmpRetCode != null && tmpRetCode.equals("0000")) {
                    return tmpBkReader;
                }
            }
        }
        return null;
    }
}
